<#include "${ftl_skin}/common/header.ftl">

<!-- 选择员工弹窗不能跨页选择 -->

<style>
.hidden_front {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 5;
	overflow: hidden;
	max-width: 300px;
	max-height:90px;
}
/*.dialog-panel-body { overflow: hidden; }*/
</style>

</head>
<body>
<div class="row ibox float-e-margins dialog-panel-body">
	<div class="ibox-content p-t0">
    <!--<div class="ibox-content" style="width: 100%;height:500px; border-top: 1px solid #eee;overflow-y:auto; ">-->
            <!--搜索栏-->
        <#if dept_id == "">
            <form id="bs-form" role="form" class="form-horizontal">
                <div class="ibox-form">
                    <!-- 防止回车提交表单刷新页面 -->
                    <input type="text" hidden="hidden"/>
                    <div class="form-box clearFix">
                        <label for="tag_title" class="col-sm-1 col-hf-8 control-label">部门 : </label>
                        <div class="col-sm-2 col-hf-20">
                            <div class="input-group date">
                            <#--<input id="dept_id" name="dept_id" type="hidden">-->
                            <#--<input id="dept_name" name="dept_name" class="form-control layer-date" placeholder="点击选择科室" value="" type="text" required onClick="selectDept();return false;" readonly>-->
                                <div class="col-sm-10 col-hf-75">
                                    <input id="dept_id" name="dept_id" value="" type="hidden">
                                    <input id="dept_name" name="dept_name" class="form-control layer-date col-lg-6" placeholder="请选择部门" value="" type="text" readonly>
                                </div>
                                <div class="ibox-tools">
                                    <a href="javascript:void(0);" onClick="selectDept();return false;"><i
                                            class="fa fa-search"></i></a>
                                    <a href="javascript:void(0);" onClick="dept_del();"><i class="fa fa-trash"></i></a>
                                </div>
                            <#--<span class="input-group-addon" onClick="dept_del();"><i class="glyphicon glyphicon-trash" aria-hidden="true"></i></span>-->
                            </div>
                        </div>

                        <label for="tag_title" class="col-sm-1 col-hf-12 control-label">用户姓名 : </label>
                        <div class="col-sm-2 col-hf-20">
                            <input type="text" placeholder="请输入用户姓名" name="user_name" id="user_name" class="form-control">
                        </div>
                        <!--查询按钮-->
                        <div class="ibox-right col-hf-8">
                            <button class="btn btn-primary" type="button" onClick="searchBSTable('bs-table', 'bs-form');return false;">查询</button>
                        </div>
                        <!--查询按钮-->
                    </div>
                </div>
            </form>
        </#if>

            <!--/搜索栏-->
            <!--列表-->
            <!--工具栏-->
            <div id="bs-toolbar" class="btn-group">
				<button class="btn btn-primary" type="button" 
					onClick="javascript:Selected(
						getValSelections('bs-table','user_name').toString(),
						getValSelections('bs-table','user_code').toString()
				);">
					选用
				</button>
                
				<button class="btn btn-info" type="button" onClick="javascript:closeDialog();">
					退出
				</button>
            </div>
            <!--/工具栏-->

            <table 	id="bs-table"
                      <#if dept_id == "">
                        data-url="${path.servicePath}user/userlist.do"
                      <#else >
                        data-url="${path.servicePath}user/userlist.do?dept_id=${dept_id!}"
                      </#if>
                      data-method="post"
                      data-response-handler="responseHandler"
                      data-pagination="true"
                      data-page-list="[10, 20, 50, 100]"
                      data-toolbar="#bs-toolbar"

                      data-side-pagination="server"
                      data-content-type="application/x-www-form-urlencoded;charset=utf-8"

                      data-click-to-select="true"
                      data-single-select="${is_single!"true"}"

                      data-classes="table table-hover table-condensed"
                      data-striped="true"
                      data-query-params="setParams">
                <thead>
                <tr>
                    <th data-field="tableid" data-checkbox="true"></th>
                    <th data-field="user_name" data-align="center" data-sortable="true">用户名称</th>
                    <th data-field="user_code" data-align="center" data-sortable="true">用户帐号</th>
                    <th data-field="mobile_phone" data-align="center" data-sortable="true">联系电话</th>
                    <th data-field="e_mail_addr" data-align="center" data-sortable="true">电子邮箱</th>
                </tr>
                </thead>
            </table>

            <!--/列表-->

			<!-- 空白占位 -->
			<!--<div style="height:500px;"></div>-->

        </div><!-- end ibox-content -->
    </div><!-- end ibox -->



<#include "${ftl_skin}/common/js.ftl">


<script type="text/javascript">
    
    var $table = $("#bs-table");  
	var selectionIds = Array();  //保存选中ids
	{  
		var strids = getDialogData().ids;
		if (strids) {
			selectionIds = strids.split(",");
		}
	}
    var allids;
    $(function(){
    	initHFForm('#formId');
        initBSTable('bs-table', {});
        //调整body高度
   		initDialogPanel();
        //--跨页选择
		         //选中事件操作数组  
		    var union = function(array,ids){  
		        $.each(ids, function (i, id) {  
		            if($.inArray(id,array)==-1){  
		                array[array.length] = id;  
		            }  
		             });  
		            return array;  
		    };  
		    //取消选中事件操作数组  
		    var difference = function(array,ids){  
		            $.each(ids, function (i, id) {  
		                 var index = $.inArray(id,array);  
		                 if(index!=-1){  
		                     array.splice(index, 1);  
		                 }  
		             });  
		            return array;  
		    };  
		    var _ = {"union":union,"difference":difference};  
		    //绑定选中事件、取消事件、全部选中、全部取消  
		    $table.on('check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table', function (e, rows) {  
		            var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {  
		                     return row.id;  
		            });  
		             func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference';  
		             selectionIds = _[func](selectionIds, ids);   
		     });  
        //--跨页选择end
    });
	//表格分页之前处理多选框数据  
    function responseHandler(res) {  
    	var re = pagerTableResponseHandler(res);
    	allids = "";
          $.each(re.rows, function (i, r) {
          	allids+=r.user_code+",";
            r.tableid = $.inArray(r.user_code, selectionIds) != -1;  //判断当前行的数据id是否存在与选中的数组，存在则将多选框状态变为true  
         });  
         allids=allids.substring(0,allids.length-1);
          return re;  
    }  
    
	//判断是否选中
	function isSelect() {
		if(selectionIds.length == 0)
			return false;
		else 
			return true;
	}
	
 	//不是进行分配而是进行员工弹窗选择时, 返回名字和id
 	function Selected(username,usercode){
 		var returnVal = {
	    	names:username,
	    	codes:usercode,
    	}
    	closeDialog(returnVal);
    }
    function cancel() {
    	$(":checkbox").attr('checked',false);
    	selectionIds = [];
    }
    	
	//选择科室
	function selectDept(){
		openDialog('select', '科室选择', '/HFDataExchange/view/dept/singleselect.do', '', 400, 450, function(){
			var returnVal = this.returnValue;
			if (returnVal) {
				$('#dept_id').val(returnVal.nodeId);
				$('#dept_name').val(returnVal.nodeName);
			}
			return false;
		});
	}
	//清空部门
    function dept_del() {
    	$('#dept_id').val('');
		$('#dept_name').val('');
    }
</script>

<#include "${ftl_skin}/common/footer.ftl">